import requests
import hashlib
import json

def get_sign(url):
	md5 = hashlib.md5()
	md5.update(url.encode('utf-8'))
	return md5.hexdigest().lower()

def get_md5(data, key):
    data_keys = data.keys()

    url = ""
    for idx,k in enumerate(sorted(data_keys)):
        if idx != 0:
            url += "&" + k + "=" + str(data[k])
        else :	
            url += k + "=" + str(data[k])   
    url += "&key=" + key
    print("原串：",url)
    sign = get_sign(url)    
    return sign

def draw():
    data = {
        "outOrderNo":"12233212312",
        "outUserId":"333",
        "channelCode":"RVG1S03S",
        "payType":"3",
        "payAccount":"test555666@paytm.com",
        "payAmount":"100.00",
    }
    key = "OORH2F2RY5R6W2TM"
    sign = get_md5(data, key)

    data["accountOwner"]=""
    data["bankCode"]=""
    data["email"]="test555666@paytm.com"
    data["mobile"]="5555566666"
    data["serverNotify"]=""
    data['sign'] = sign

    BASE_URL="https://pay.bmartpay.com/api/payment/trans"
    # headers = {'Content-Type': 'application/json'}
    print("请求地址：",BASE_URL)
    print("post的form参数：",json.dumps(data))
    resp = requests.post(BASE_URL, data=data)
    print("响应结果",resp.text)

def main():
    draw()
    
if __name__ == "__main__":
    main()